package com.yeshine.opendata.entity;

import com.yeshine.opendata.core.EntityBase;
import com.yeshine.opendata.utils.OfficeExtractor;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

/**
 * Created by taohj on 2014/6/27.
 * 数据
 */
public class Data extends EntityBase {

    private Integer id;

    //标题
    private String title;
    //简介
    private String description;
    //标签
    private String tags;
    //授权信息
    private String license;

    //存储形式
    private SysDictionary storage;
    //数据url
    private String url;

    //类型 文件格式
    private String fileFormat;
    //是否公开
    private SysDictionary visibility;
    //当前状态
    private SysDictionary status;

    //
    private SysDictionary auditStatus;

    //当前版本
    private String version;

    //唯一标识列
    private String GUID;

    //创建人
    private User creater;
    //创建时间
    private Date createTime;

    //数据集
    private DataSet dataset;

    //所属组织
    private Org org;


    private User updater;

    private Date updateTime;



    private Integer [] orgIds;

    private String [] formats;

    private Integer [] themes;

    private MultipartFile file;

    public Data() {
    }

    public Data(int id) {
        this.id = id;
    }


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public String getLicense() {
        return license;
    }

    public void setLicense(String license) {
        this.license = license;
    }

    public Org getOrg() {
        return org;
    }

    public void setOrg(Org org) {
        this.org = org;
    }



    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }



    public String getFileFormat() {
        return fileFormat;
    }

    public void setFileFormat(String fileFormat) {
        this.fileFormat = fileFormat;
    }

    public SysDictionary getVisibility() {
        return visibility;
    }

    public void setVisibility(SysDictionary visibility) {
        this.visibility = visibility;
    }

    public SysDictionary getStatus() {
        return status;
    }

    public void setStatus(SysDictionary status) {
        this.status = status;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getGUID() {
        return GUID;
    }

    public void setGUID(String GUID) {
        this.GUID = GUID;
    }

    public User getCreater() {
        return creater;
    }

    public void setCreater(User creater) {
        this.creater = creater;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public DataSet getDataset() {
        return dataset;
    }

    public void setDataset(DataSet dataset) {
        this.dataset = dataset;
    }

    public Integer[] getOrgIds() {
        return orgIds;
    }

    public void setOrgIds(Integer[] orgIds) {
        this.orgIds = orgIds;
    }

    public String[] getFormats() {
        return formats;
    }

    public void setFormats(String[] formats) {
        this.formats = formats;
    }

    public MultipartFile getFile() {
        return file;
    }

    public void setFile(MultipartFile file) {
        this.file = file;
    }


    public SysDictionary getStorage() {
        return storage;
    }

    public void setStorage(SysDictionary storage) {
        this.storage = storage;
    }

    public SysDictionary getAuditStatus() {
        return auditStatus;
    }

    public void setAuditStatus(SysDictionary auditStatus) {
        this.auditStatus = auditStatus;
    }


    public User getUpdater() {
        return updater;
    }

    public void setUpdater(User updater) {
        this.updater = updater;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Integer[] getThemes() {
        return themes;
    }

    public void setThemes(Integer[] themes) {
        this.themes = themes;
    }

    public  String getPreview(){
        if (StringUtils.hasLength(url)){
            if(OfficeExtractor.sets.contains(url.substring(url.lastIndexOf(".")))){
                return  url.substring(0,url.lastIndexOf("."))+".html";
            }else{
                return  url;
            }
        }
        return null;

   }

    public static void main(String[] args) {

        String fileName="3.doc";
        System.out.println(fileName.substring(0,fileName.lastIndexOf("."))+".html");

    }

}

